import os

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QColor, QPalette
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
from PyQt5.QtWidgets import QMainWindow, QSlider, QTabWidget, QVBoxLayout, QGridLayout
from PyQt5.QtWidgets import (QAction, QApplication, QHBoxLayout, QLabel,
                             QWidget, qApp)
from PyQt5.QtCore import QPropertyAnimation, QEasingCurve, Qt, pyqtSignal, QFile
from modules import *
from components import *
from .play_bar.play_bar import PlayerBar
from .album.album_detail import AlbumDetail
from .windows.mini_window import MiniWindow
import resources_rc
class Ui_MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        # self.setWindowFlags(Qt.FramelessWindowHint)      #隐藏窗口边框
        # 去掉标题栏
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowMinMaxButtonsHint)
        self.history = -1
        # MainWindow.setWindowFlags(Qt.CustomizeWindowHint)
        self.setupUi()
        self.initStyle()
        self.initGrip()
        # self.initSlider()
        self.getAlbums()
        self.setQss()
        self.initHandle()
        self.initSignals()
        self.initPlayer()
        self.show()

    def setupUi(self):
        self.setObjectName("MainWindow")
        self.resize(1240, 809)
        font = QtGui.QFont()
        font.setPointSize(9)
        self.setFont(font)
        self.MainWidget = QtWidgets.QWidget(self)
        self.MainWidget.setObjectName("MainWidget")
        self.MainLayout = QtWidgets.QVBoxLayout(self.MainWidget)
        self.MainLayout.setContentsMargins(0, 0, 0, 0)
        self.MainLayout.setSpacing(0)
        self.MainLayout.setObjectName("MainLayout")
        self.MainFrame = QtWidgets.QFrame(self.MainWidget)
        self.MainFrame.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.MainFrame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.MainFrame.setObjectName("MainFrame")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.MainFrame)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setSpacing(0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.LeftMenu = QtWidgets.QFrame(self.MainFrame)
        self.LeftMenu.setMinimumSize(QtCore.QSize(60, 0))
        self.LeftMenu.setMaximumSize(QtCore.QSize(60, 16777215))
        font = QtGui.QFont()
        font.setFamily("Segoe UI")
        font.setPointSize(10)
        self.LeftMenu.setFont(font)
        self.LeftMenu.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.LeftMenu.setFrameShadow(QtWidgets.QFrame.Raised)
        self.LeftMenu.setObjectName("LeftMenu")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.LeftMenu)
        self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_2.setSpacing(0)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.LogoBox = QtWidgets.QFrame(self.LeftMenu)
        self.LogoBox.setMinimumSize(QtCore.QSize(0, 50))
        self.LogoBox.setMaximumSize(QtCore.QSize(16777215, 50))
        self.LogoBox.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.LogoBox.setFrameShadow(QtWidgets.QFrame.Raised)
        self.LogoBox.setObjectName("LogoBox")
        self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.LogoBox)
        self.verticalLayout_4.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_4.setSpacing(0)
        self.verticalLayout_4.setObjectName("verticalLayout_4")
        self.BackButton = QtWidgets.QPushButton(self.LogoBox)
        self.BackButton.setMinimumSize(QtCore.QSize(0, 50))
        self.BackButton.setText("")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/icons/images/icon/back.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.BackButton.setIcon(icon)
        self.BackButton.setIconSize(QtCore.QSize(28, 28))
        self.BackButton.setObjectName("BackButton")
        self.verticalLayout_4.addWidget(self.BackButton)
        self.verticalLayout_2.addWidget(self.LogoBox)
        self.LeftMenuFrame = QtWidgets.QFrame(self.LeftMenu)
        self.LeftMenuFrame.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.LeftMenuFrame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.LeftMenuFrame.setObjectName("LeftMenuFrame")
        self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.LeftMenuFrame)
        self.verticalLayout_3.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_3.setSpacing(0)
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        self.toggleBox = QtWidgets.QFrame(self.LeftMenuFrame)
        self.toggleBox.setMaximumSize(QtCore.QSize(16777215, 45))
        font = QtGui.QFont()
        font.setFamily("Segoe UI")
        font.setPointSize(10)
        self.toggleBox.setFont(font)
        self.toggleBox.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.toggleBox.setFrameShadow(QtWidgets.QFrame.Raised)
        self.toggleBox.setObjectName("toggleBox")
        self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.toggleBox)
        self.verticalLayout_5.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_5.setSpacing(0)
        self.verticalLayout_5.setObjectName("verticalLayout_5")
        self.toggleButton = QtWidgets.QPushButton(self.toggleBox)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.toggleButton.sizePolicy().hasHeightForWidth())
        self.toggleButton.setSizePolicy(sizePolicy)
        self.toggleButton.setMinimumSize(QtCore.QSize(0, 45))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(113, 126, 149))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
        brush = QtGui.QBrush(QtGui.QColor(37, 41, 48))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(113, 126, 149))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(113, 126, 149))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush)
        brush = QtGui.QBrush(QtGui.QColor(37, 41, 48))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(37, 41, 48))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(113, 126, 149))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText, brush)
        brush = QtGui.QBrush(QtGui.QColor(113, 126, 149))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
        brush = QtGui.QBrush(QtGui.QColor(37, 41, 48))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(113, 126, 149))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(113, 126, 149))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush)
        brush = QtGui.QBrush(QtGui.QColor(37, 41, 48))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(37, 41, 48))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(113, 126, 149))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.PlaceholderText, brush)
        brush = QtGui.QBrush(QtGui.QColor(113, 126, 149))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
        brush = QtGui.QBrush(QtGui.QColor(37, 41, 48))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
        brush = QtGui.QBrush(QtGui.QColor(113, 126, 149))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(113, 126, 149))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush)
        brush = QtGui.QBrush(QtGui.QColor(37, 41, 48))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(37, 41, 48))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(113, 126, 149))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.PlaceholderText, brush)
        self.toggleButton.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("Segoe UI")
        font.setPointSize(10)
        self.toggleButton.setFont(font)
        self.toggleButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.toggleButton.setMouseTracking(True)
        self.toggleButton.setStyleSheet("")
        self.toggleButton.setText("")
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(":/icons/images/icon/menu.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.toggleButton.setIcon(icon1)
        self.toggleButton.setIconSize(QtCore.QSize(28, 28))
        self.toggleButton.setObjectName("toggleButton")
        self.verticalLayout_5.addWidget(self.toggleButton)
        self.verticalLayout_3.addWidget(self.toggleBox)
        self.topMenu = QtWidgets.QFrame(self.LeftMenuFrame)
        self.topMenu.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.topMenu.setFrameShadow(QtWidgets.QFrame.Raised)
        self.topMenu.setObjectName("topMenu")
        self.verticalLayout_6 = QtWidgets.QVBoxLayout(self.topMenu)
        self.verticalLayout_6.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_6.setSpacing(0)
        self.verticalLayout_6.setObjectName("verticalLayout_6")
        self.MusicButton = QtWidgets.QPushButton(self.topMenu)
        self.MusicButton.setMinimumSize(QtCore.QSize(0, 45))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.MusicButton.setFont(font)
        self.MusicButton.setStyleSheet("")
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap(":/icons/images/icon/music.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.MusicButton.setIcon(icon2)
        self.MusicButton.setIconSize(QtCore.QSize(26, 26))
        self.MusicButton.setObjectName("MusicButton")
        self.verticalLayout_6.addWidget(self.MusicButton)
        self.HistoryButton = QtWidgets.QPushButton(self.topMenu)
        self.HistoryButton.setMinimumSize(QtCore.QSize(0, 45))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.HistoryButton.setFont(font)
        self.HistoryButton.setStyleSheet("")
        icon3 = QtGui.QIcon()
        icon3.addPixmap(QtGui.QPixmap(":/icons/images/icon/history.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.HistoryButton.setIcon(icon3)
        self.HistoryButton.setIconSize(QtCore.QSize(26, 26))
        self.HistoryButton.setObjectName("HistoryButton")
        self.verticalLayout_6.addWidget(self.HistoryButton)
        self.SettingButton = QtWidgets.QPushButton(self.topMenu)
        self.SettingButton.setMinimumSize(QtCore.QSize(0, 45))
        icon4 = QtGui.QIcon()
        icon4.addPixmap(QtGui.QPixmap(":/icons/images/icon/settings.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.SettingButton.setIcon(icon4)
        self.SettingButton.setIconSize(QtCore.QSize(26, 26))
        self.SettingButton.setObjectName("SettingButton")
        self.verticalLayout_6.addWidget(self.SettingButton)
        self.frame_3 = QtWidgets.QFrame(self.topMenu)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.frame_3.sizePolicy().hasHeightForWidth())
        self.frame_3.setSizePolicy(sizePolicy)
        self.frame_3.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_3.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_3.setObjectName("frame_3")
        self.verticalLayout_6.addWidget(self.frame_3)
        self.verticalLayout_3.addWidget(self.topMenu)
        self.verticalLayout_2.addWidget(self.LeftMenuFrame)
        self.horizontalLayout.addWidget(self.LeftMenu)
        self.ContentBox = QtWidgets.QFrame(self.MainFrame)
        self.ContentBox.setStyleSheet("")
        self.ContentBox.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.ContentBox.setFrameShadow(QtWidgets.QFrame.Raised)
        self.ContentBox.setObjectName("ContentBox")
        self.verticalLayout_11 = QtWidgets.QVBoxLayout(self.ContentBox)
        self.verticalLayout_11.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_11.setSpacing(0)
        self.verticalLayout_11.setObjectName("verticalLayout_11")
        self.TitleBar = QtWidgets.QFrame(self.ContentBox)
        self.TitleBar.setMinimumSize(QtCore.QSize(0, 50))
        self.TitleBar.setMaximumSize(QtCore.QSize(16777215, 50))
        self.TitleBar.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.TitleBar.setFrameShadow(QtWidgets.QFrame.Raised)
        self.TitleBar.setObjectName("TitleBar")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.TitleBar)
        self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_5.setSpacing(0)
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.TitleText = QtWidgets.QFrame(self.TitleBar)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.TitleText.sizePolicy().hasHeightForWidth())
        self.TitleText.setSizePolicy(sizePolicy)
        self.TitleText.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.TitleText.setFrameShadow(QtWidgets.QFrame.Raised)
        self.TitleText.setObjectName("TitleText")
        self.horizontalLayout_5.addWidget(self.TitleText)
        self.TitleButton = QtWidgets.QFrame(self.TitleBar)
        self.TitleButton.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.TitleButton.setFrameShadow(QtWidgets.QFrame.Raised)
        self.TitleButton.setObjectName("TitleButton")
        self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.TitleButton)
        self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_6.setSpacing(0)
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
        self.MinimizeButton = QtWidgets.QPushButton(self.TitleButton)
        self.MinimizeButton.setMinimumSize(QtCore.QSize(36, 36))
        self.MinimizeButton.setMaximumSize(QtCore.QSize(36, 36))
        self.MinimizeButton.setText("")
        icon5 = QtGui.QIcon()
        icon5.addPixmap(QtGui.QPixmap(":/icons/images/icon/minimize.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.MinimizeButton.setIcon(icon5)
        self.MinimizeButton.setIconSize(QtCore.QSize(24, 24))
        self.MinimizeButton.setObjectName("MinimizeButton")
        self.horizontalLayout_6.addWidget(self.MinimizeButton)
        self.MaximizeButton = QtWidgets.QPushButton(self.TitleButton)
        self.MaximizeButton.setMinimumSize(QtCore.QSize(36, 36))
        self.MaximizeButton.setMaximumSize(QtCore.QSize(36, 36))
        self.MaximizeButton.setText("")
        icon6 = QtGui.QIcon()
        icon6.addPixmap(QtGui.QPixmap(":/icons/images/icon/maximize.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.MaximizeButton.setIcon(icon6)
        self.MaximizeButton.setIconSize(QtCore.QSize(24, 24))
        self.MaximizeButton.setObjectName("MaximizeButton")
        self.horizontalLayout_6.addWidget(self.MaximizeButton)
        self.CloseButton = QtWidgets.QPushButton(self.TitleButton)
        self.CloseButton.setMinimumSize(QtCore.QSize(36, 36))
        self.CloseButton.setMaximumSize(QtCore.QSize(36, 36))
        self.CloseButton.setText("")
        icon7 = QtGui.QIcon()
        icon7.addPixmap(QtGui.QPixmap(":/icons/images/icon/close.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.CloseButton.setIcon(icon7)
        self.CloseButton.setIconSize(QtCore.QSize(24, 24))
        self.CloseButton.setObjectName("CloseButton")
        self.horizontalLayout_6.addWidget(self.CloseButton)
        self.horizontalLayout_5.addWidget(self.TitleButton)
        self.verticalLayout_11.addWidget(self.TitleBar)
        self.Content = QtWidgets.QFrame(self.ContentBox)
        self.Content.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.Content.setFrameShadow(QtWidgets.QFrame.Raised)
        self.Content.setObjectName("Content")
        self.verticalLayout_8 = QtWidgets.QVBoxLayout(self.Content)
        self.verticalLayout_8.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_8.setSpacing(0)
        self.verticalLayout_8.setObjectName("verticalLayout_8")
        self.PageTitle = QtWidgets.QFrame(self.Content)
        self.PageTitle.setMinimumSize(QtCore.QSize(0, 40))
        self.PageTitle.setMaximumSize(QtCore.QSize(16777215, 40))
        self.PageTitle.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.PageTitle.setFrameShadow(QtWidgets.QFrame.Raised)
        self.PageTitle.setObjectName("PageTitle")
        self.verticalLayout_14 = QtWidgets.QVBoxLayout(self.PageTitle)
        self.verticalLayout_14.setContentsMargins(15, 0, 0, 0)
        self.verticalLayout_14.setSpacing(0)
        self.verticalLayout_14.setObjectName("verticalLayout_14")
        self.TitleLabel = QtWidgets.QLabel(self.PageTitle)
        font = QtGui.QFont()
        font.setPointSize(28)
        self.TitleLabel.setFont(font)
        self.TitleLabel.setObjectName("TitleLabel")
        self.verticalLayout_14.addWidget(self.TitleLabel)
        self.verticalLayout_8.addWidget(self.PageTitle)
        self.ContentStackedWidget = QtWidgets.QStackedWidget(self.Content)
        self.ContentStackedWidget.setStyleSheet("")
        self.ContentStackedWidget.setObjectName("ContentStackedWidget")
        self.MusicPage = QtWidgets.QWidget()
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.MusicPage.sizePolicy().hasHeightForWidth())
        self.MusicPage.setSizePolicy(sizePolicy)
        self.MusicPage.setStyleSheet("")
        self.MusicPage.setObjectName("MusicPage")
        self.verticalLayout_12 = QtWidgets.QVBoxLayout(self.MusicPage)
        self.verticalLayout_12.setContentsMargins(20, 10, 20, 0)
        self.verticalLayout_12.setSpacing(0)
        self.verticalLayout_12.setObjectName("verticalLayout_12")
        self.MusicTabWidget = QtWidgets.QTabWidget(self.MusicPage)
        font = QtGui.QFont()
        font.setFamily("Microsoft YaHei UI")
        font.setPointSize(15)
        font.setBold(False)
        font.setUnderline(False)
        font.setWeight(50)
        font.setKerning(True)
        self.MusicTabWidget.setFont(font)
        self.MusicTabWidget.setTabPosition(QtWidgets.QTabWidget.North)
        self.MusicTabWidget.setTabShape(QtWidgets.QTabWidget.Rounded)
        self.MusicTabWidget.setElideMode(QtCore.Qt.ElideLeft)
        self.MusicTabWidget.setDocumentMode(True)
        self.MusicTabWidget.setTabsClosable(False)
        self.MusicTabWidget.setMovable(False)
        self.MusicTabWidget.setTabBarAutoHide(False)
        self.MusicTabWidget.setObjectName("MusicTabWidget")
        self.SongsWidget = QtWidgets.QWidget()
        self.SongsWidget.setObjectName("SongsWidget")
        self.SongsWidgetLayout = QtWidgets.QVBoxLayout(self.SongsWidget)
        self.SongsWidgetLayout.setContentsMargins(0, 0, 0, 0)
        self.SongsWidgetLayout.setSpacing(0)
        self.SongsWidgetLayout.setObjectName("SongsWidgetLayout")

        self.SongsList = TableWidget()
        songsList = LocalMusic.getAllSongsList(self)
        self.SongsList.loadSongsList(songsList)
        # self.AlbumContentLayout.addWidget(self.SongsList)

        self.SongsWidgetLayout.addWidget(self.SongsList)
        self.MusicTabWidget.addTab(self.SongsWidget, "")
        self.AlbumsWidget = QtWidgets.QWidget()
        self.AlbumsWidget.setObjectName("AlbumsWidget")
        self.AlbumsWidgetLayout = QtWidgets.QVBoxLayout(self.AlbumsWidget)
        self.AlbumsWidgetLayout.setContentsMargins(0, 0, 0, 0)
        self.AlbumsWidgetLayout.setSpacing(0)
        self.AlbumsWidgetLayout.setObjectName("AlbumsWidgetLayout")
        self.AlbumsList = QtWidgets.QScrollArea(self.AlbumsWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.AlbumsList.sizePolicy().hasHeightForWidth())
        self.AlbumsList.setSizePolicy(sizePolicy)
        self.AlbumsList.setWidgetResizable(True)
        self.AlbumsList.setObjectName("AlbumsList")
        self.AlbumsWidgetContents = QtWidgets.QWidget()
        self.AlbumsWidgetContents.setGeometry(QtCore.QRect(0, 0, 1140, 582))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.AlbumsWidgetContents.sizePolicy().hasHeightForWidth())
        self.AlbumsWidgetContents.setSizePolicy(sizePolicy)
        self.AlbumsWidgetContents.setObjectName("AlbumsWidgetContents")
        self.AlbumListLayout = QtWidgets.QVBoxLayout(self.AlbumsWidgetContents)
        self.AlbumListLayout.setContentsMargins(0, 0, 0, 0)
        self.AlbumListLayout.setObjectName("AlbumListLayout")
        self.AlbumsList.setWidget(self.AlbumsWidgetContents)
        self.AlbumsWidgetLayout.addWidget(self.AlbumsList)
        self.MusicTabWidget.addTab(self.AlbumsWidget, "")
        self.verticalLayout_12.addWidget(self.MusicTabWidget)
        self.ContentStackedWidget.addWidget(self.MusicPage)
        self.HistoryPage = QtWidgets.QWidget()
        self.HistoryPage.setStyleSheet("background-color: rgb(255, 170, 255);")
        self.HistoryPage.setObjectName("HistoryPage")
        self.verticalLayout_13 = QtWidgets.QVBoxLayout(self.HistoryPage)
        self.verticalLayout_13.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_13.setSpacing(0)
        self.verticalLayout_13.setObjectName("verticalLayout_13")
        self.frame_4 = QtWidgets.QFrame(self.HistoryPage)
        self.frame_4.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_4.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_4.setObjectName("frame_4")
        self.verticalLayout_13.addWidget(self.frame_4)
        self.frame = QtWidgets.QFrame(self.HistoryPage)
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.verticalLayout_13.addWidget(self.frame)
        self.ContentStackedWidget.addWidget(self.HistoryPage)
        self.SettingPage = QtWidgets.QWidget()
        self.SettingPage.setObjectName("SettingPage")
        self.ContentStackedWidget.addWidget(self.SettingPage)
        self.AlbumDetailPage = AlbumDetail()
        self.AlbumDetailPage.setObjectName("AlbumDetailPage")
        self.ContentStackedWidget.addWidget(self.AlbumDetailPage)
        self.verticalLayout_8.addWidget(self.ContentStackedWidget)
        self.verticalLayout_11.addWidget(self.Content)
        self.horizontalLayout.addWidget(self.ContentBox)
        self.MainLayout.addWidget(self.MainFrame)

        self.PlayBar = PlayerBar()
        self.MainLayout.addWidget(self.PlayBar)
        self.setCentralWidget(self.MainWidget)

        self.retranslateUi()
        self.ContentStackedWidget.setCurrentIndex(0)
        self.MusicTabWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(self)

    def retranslateUi(self):
        _translate = QtCore.QCoreApplication.translate
        self.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.MusicButton.setText(_translate("MainWindow", "   我的音乐"))
        self.HistoryButton.setText(_translate("MainWindow", "   播放历史"))
        self.SettingButton.setText(_translate("MainWindow", "   设置"))
        self.TitleLabel.setText(_translate("MainWindow", "我的音乐"))
        self.MusicTabWidget.setTabText(self.MusicTabWidget.indexOf(self.SongsWidget), _translate("MainWindow", "歌曲"))
        self.MusicTabWidget.setTabText(self.MusicTabWidget.indexOf(self.AlbumsWidget), _translate("MainWindow", "专辑"))

    def initHandle(self):
        self.toggleButton.clicked.connect(lambda: Menu.toggleMenu(self, True))
        self.MinimizeButton.clicked.connect(lambda: TitleHandle.showMin(self))
        self.MaximizeButton.clicked.connect(lambda: TitleHandle.showRestoredWindow(self))
        self.CloseButton.clicked.connect(self.close)
        self.MusicButton.clicked.connect(lambda: self.ContentStackedWidget.setCurrentIndex(0))
        self.HistoryButton.clicked.connect(lambda: self.ContentStackedWidget.setCurrentIndex(1))
        self.BackButton.clicked.connect(CommonSignal.backHistorySignal)

    def initSignals(self):
        CommonSignal.playSignal.connect(self.playMusic)
        CommonSignal.volumeChangedSignal.connect(self.changeVolume)
        CommonSignal.volumeButtonSignal.connect(self.setMute)
        CommonSignal.progressSliderMovedSignal.connect(self.onProgressSliderMoved)
        CommonSignal.showDetailSignal.connect(self.albumDetail)
        CommonSignal.backHistorySignal.connect(self.back)
        CommonSignal.changeTitleColorSignal.connect(self.changeColor)
        CommonSignal.playAlbumSignal.connect(self.playAlbum)
        CommonSignal.playNextSignal.connect(self.playNext)
        CommonSignal.playPreSignal.connect(self.playPre)
        CommonSignal.playSongSignal.connect(self.PlaySong)
        CommonSignal.playChooseSongSignal.connect(self.playChooseSong)
        CommonSignal.miniWindowOpenSignal.connect(self.openMiniWindow)
        CommonSignal.miniWindowCloseSignal.connect(self.closeMiniWindow)
        # self.MusicTabWidget.currentChanged.connect(self.tabchange)

    # def tabchange(self):
    #     if self.MusicTabWidget.currentIndex() == 0:
    #         CommonSignal.musicTabChangedSignal.emit()

    def initGrip(self):
        self.left_grip = CustomGrip(self, Qt.Edge.LeftEdge, True)
        self.right_grip = CustomGrip(self, Qt.Edge.RightEdge, True)
        self.top_grip = CustomGrip(self, Qt.Edge.TopEdge, True)
        self.bottom_grip = CustomGrip(self, Qt.Edge.BottomEdge, True)

    def initStyle(self):
        self.BackButton.hide()
    def setQss(self):
        f = QFile(":/static/qss/main_window.qss")
        f.open(QFile.ReadOnly)
        self.setStyleSheet(str(f.readAll(), encoding='utf-8'))
        f.close()

    def getAlbums(self):
        artistList = LocalMusic.getLocalArtist(self)
        for info in artistList:
            artist = info[0]
            self.AlbumListLayout.addWidget(AlbumsSortBox(artist))
        # self.AlbumListLayout.addWidget(AlbumsSortBox())
        # self.AlbumListLayout.addWidget(AlbumsSortBox())

    def mousePressEvent(self, evt):
        # 获取鼠标当前的坐标
        self.mouse_x = evt.globalX()
        self.mouse_y = evt.globalY()
        print(evt.globalX())
        # 获取窗体当前坐标
        self.origin_x = self.x()
        self.origin_y = self.y()

    # 2.鼠标移动事件
    def mouseMoveEvent(self, evt):
        # print('--------mouseMoveEvent-------')
        # 计算鼠标移动的x，y位移
        if hasattr(self, 'mouse_x'):
            move_x = evt.globalX() - self.mouse_x
            move_y = evt.globalY() - self.mouse_y

            # 计算窗体更新后的坐标：更新后的坐标 = 原本的坐标 + 鼠标的位移
            dest_x = self.origin_x + move_x
            dest_y = self.origin_y + move_y

            # 移动窗体
            self.move(dest_x, dest_y)

    def resizeEvent(self, event):
        # Update Size Grips
        # print('--------resizeEvent-------')
        self.left_grip.setGeometry(0, 10, 10, self.height())
        self.right_grip.setGeometry(self.width() - 10, 10, 10, self.height())
        self.top_grip.setGeometry(0, 0, self.width(), 10)
        self.bottom_grip.setGeometry(0, self.height() - 10, self.width(), 10)

    def initPlayer(self):

        self.player = QMediaPlayer(self)
        self.playing = False  # 播放状态初始化为否
        self.pause = False
        self.player.positionChanged.connect(self.onPlayerPositionChanged)
        self.player.durationChanged.connect(self.onPlayerDurationChanged)
        self.mute = False


    # 播放歌曲
    def playMusic(self,info = None):
        print('----------playMusic---------')
        try:
            if self.playing is False:
                self.playing = True # 设置播放状态为是
                if info:
                    pass
                else:
                    info = LocalMusic.getPlayingInfo(self)
                path = info[5]
                CommonSignal.changeSongSignal.emit(info[0])
                CommonSignal.changeSongInfoSignal.emit(info[1], info[4])
                cover = Config.coverPath + info[4] + '-' + info[2] + '.jpg'
                CommonSignal.changeCoverSignal.emit(cover)
                r, g, b = DominantColor.getDominantColor(cover)
                CommonSignal.changePlayBarColorSignal.emit(QColor(r, g, b))
                CommonSignal.totalDurationChangeSignal.emit(info[6])
                content = QMediaContent(QtCore.QUrl.fromLocalFile(path))
                self.player.setMedia(content)
                self.player.setVolume(50)
                self.player.play()
                icon = QtGui.QIcon()
                icon.addPixmap(QtGui.QPixmap(":/icons/images/icon/pause_1.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
                self.PlayBar.PlayButton.setIcon(icon)

                if hasattr(self, 'miniWindow'):
                    icon1 = QtGui.QIcon()
                    icon1.addPixmap(QtGui.QPixmap(":/icons/images/icon/pause_3.png"), QtGui.QIcon.Normal,
                                   QtGui.QIcon.Off)
                    self.miniWindow.MiniPlayBtn.setIcon(icon1)

            else:
                if self.pause:
                    self.player.play()
                    self.pause = False
                    icon = QtGui.QIcon()
                    icon.addPixmap(QtGui.QPixmap(":/icons/images/icon/pause_1.png"), QtGui.QIcon.Normal,
                                   QtGui.QIcon.Off)
                    self.PlayBar.PlayButton.setIcon(icon)

                    if hasattr(self, 'miniWindow'):
                        icon1 = QtGui.QIcon()
                        icon1.addPixmap(QtGui.QPixmap(":/icons/images/icon/pause_3.png"), QtGui.QIcon.Normal,
                                        QtGui.QIcon.Off)
                        self.miniWindow.MiniPlayBtn.setIcon(icon1)
                else:
                    self.player.pause()
                    self.pause = True
                    # self.playing = False  # 设置播放状态为否
                    icon = QtGui.QIcon()
                    icon.addPixmap(QtGui.QPixmap(":/icons/images/icon/play_1.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
                    self.PlayBar.PlayButton.setIcon(icon)

                    if hasattr(self, 'miniWindow'):
                        icon1 = QtGui.QIcon()
                        icon1.addPixmap(QtGui.QPixmap(":/icons/images/icon/play_6.png"), QtGui.QIcon.Normal,
                                        QtGui.QIcon.Off)
                        self.miniWindow.MiniPlayBtn.setIcon(icon1)


        except Exception as e:
            print(repr(e))

    def playAlbum(self,album,artist):
        # print(albumId)
        songsList = LocalMusic.getAlbumSongsList(self,album,artist)
        LocalMusic.setPlayList(self, list(songsList))
        self.playing = False
        self.playMusic()

    def playChooseSong(self, songsList, playing):
        LocalMusic.setPlayList(self, songsList, playing)
        self.playing = False
        self.playMusic()

    def playPre(self):
        info = LocalMusic.playingPre(self)
        self.playing = False
        if info:
            self.playMusic(info)

    def playNext(self):
        info = LocalMusic.playingNext(self)
        self.playing = False
        if info:
            self.playMusic(info)

    def PlaySong(self,songId):
        print(songId)

    # 修改音量
    def changeVolume(self,volume):
        print(volume)
        self.player.setVolume(volume)
        self.PlayBar.volume = volume

    # 设置、取消静音
    def setMute(self):
        if self.mute == True:
            self.mute = False
            icon = QtGui.QIcon()
            icon.addPixmap(QtGui.QPixmap(":/icons/images/icon/sound-on_1.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.PlayBar.VolumeButton.setIcon(icon)
            if self.PlayBar.volume > 0:
                self.player.setVolume(self.PlayBar.volume)
            else:
                self.PlayBar.volume = 10
                self.player.setVolume(self.PlayBar.volume)
                self.PlayBar.VolumeSlider.setProperty("value", self.PlayBar.volume)
        else:
            self.mute = True
            self.player.setVolume(0)
            icon = QtGui.QIcon()
            icon.addPixmap(QtGui.QPixmap(":/icons/images/icon/sound-off_1.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.PlayBar.VolumeButton.setIcon(icon)

    # 歌曲进度变化事件
    def onPlayerPositionChanged(self,position):
        seconds = int(round(position/1000,0))
        m, s = divmod(seconds, 60)
        h, m = divmod(m, 60)
        timeFormat = ''
        if h > 0:
            timeFormat = timeFormat + str(h) + ':'

        if m > 0:
            timeFormat = timeFormat + str(m) + ':'
        else:
            timeFormat = "0:"

        if s > 0:
            if s < 10:
                timeFormat = timeFormat + '0' + str(s)
            else:
                timeFormat = timeFormat + str(s)
        else:
            timeFormat = timeFormat + '00'
        CommonSignal.currentDurationChangeSignal.emit(timeFormat)
        self.PlayBar.ProgressSlider.setValue(position)
        # 播放结束自动进入下一首
        if self.player.duration() > 0 and position == self.player.duration():
            self.playNext()



    # 获取歌曲时长
    def onPlayerDurationChanged(self,duration):
        # print('-----duration-----')
        # print(duration)
        if duration > 0:
            self.PlayBar.ProgressSlider.setRange(0, duration)

    def onProgressSliderMoved(self,position):
        print('------move-position-------')
        print(position)
        self.player.setPosition(position)

    def albumDetail(self,albumId: int):

        self.AlbumDetailPage.loadData(albumId)
        self.history = 0
        self.PageTitle.hide()
        self.BackButton.show()
        self.ContentStackedWidget.setCurrentIndex(3)

    def back(self):
        if self.history != -1:
            self.ContentStackedWidget.setCurrentIndex(self.history)
            self.BackButton.hide()
            self.history = -1
            self.changeColor(QColor(240,240,240))

    def changeColor(self,color):
        palette = QPalette()
        palette.setColor(self.TitleBar.backgroundRole(), color)
        self.TitleBar.setAutoFillBackground(True)
        self.TitleBar.setPalette(palette)

    def openMiniWindow(self):
        print('-------openMiniWindow------')
        print(self.pause)

        self.miniWindow = MiniWindow()
        self.miniWindow.show()
        self.hide()
        if self.pause:
            pass
        else:
            icon = QtGui.QIcon()
            icon.addPixmap(QtGui.QPixmap(":/icons/images/icon/pause_3.png"), QtGui.QIcon.Normal,
                            QtGui.QIcon.Off)
            self.miniWindow.MiniPlayBtn.setIcon(icon)


    def closeMiniWindow(self):
        print('-----------closeMiniWindow-----------')
        self.show()
        self.miniWindow.hide()
